<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/12
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title><spring:message code='usercenter.index.title' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<jsp:include page="../public/header.jsp"></jsp:include>
<jsp:include page="../usercenter/leftMenu.jsp"></jsp:include>
<div class="member_box">
    <div class="member_title" id="member_title">
        <ul>
            <li stype="1" <c:if test="${type==1}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,1);changeTile(1);"><spring:message code='usercenter.taskManager.msg1' /></a></li>
            <li stype="2" <c:if test="${type==2}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,2);changeTile(2);"><spring:message code='usercenter.taskManager.msg2' /></a></li>
            <li stype="3" <c:if test="${type==3}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,3);changeTile(3);"><spring:message code='usercenter.taskManager.msg3' /></a></li>
            <li stype="4" <c:if test="${type==4}">class="hover"</c:if>><a href="javascript:void(0);" onclick="historyTask();changeTile(4);"><spring:message code='usercenter.taskManager.msg4' /></a></li>
        </ul>
    </div>
    <div class="member_projectlist">
        <ul id="tasks">

        </ul>
        <div id="kkpager" style="text-align: center"></div>
    </div>
</div>

<link href="${path}/plugins/page/kkpager.css" rel="stylesheet">
<script src="${path}/plugins/page/kkpager.js" type="text/javascript"></script>
<script src="${path}/js/jquery.cookie.js" type="text/javascript"></script>
<script>
    var pageSize = 10;
    function changeTile(type){
        $("#member_title ul li").each(function(){
            if($(this).attr("stype")==type){
                $(this).addClass("hover");
            }else{
                $(this).removeClass("hover");
            }
        });
    }
    function initBeanInfo(page, rows,type) {
        //异步获取生产计划
        pageSize = rows;
        $.post("${path}/usercenter/getItemInfo.html", {
            page: page,
            rows: rows,
            type: type
        }, function (data) {
            var list = data.pageInfo.list;
            var htmlstr = "";
            if (list != null) {
                for (var i = 0; i < list.length; i++) {
                    var obj = list[i];
                    var budgetMsg = "￥" + obj.budget;
                    if(obj.budget == -1){
                        budgetMsg = "<spring:message code='usercenter.taskManager.msg5' />";
                    }

                    htmlstr+='<li class="clearfix">'+
                            '<div class="p_img"><img src="${path}/'+obj.pic+'" width="170" height="104"  onclick="window.location=\'${path}/taskdetail/index.html?taskId='+obj.itemId+'\'" style="cursor: pointer"></div>'+
                            '<div class="p_con clearfix">'+
                            '<h3>'+obj.title+'</h3>'+
                            '<div class="p_pcon">'+obj.description+
                            '</div>'+
                            '<div class="p_money">'+
                            '<p><em class="price">'+budgetMsg+'</em></p>'+
                            '<p><em>';
                    if(obj.progress == 105105){
                        htmlstr+='<spring:message code='usercenter.taskManager.msg6' />';
                    }else if(obj.progress == 105107){
                        htmlstr+='<spring:message code='usercenter.taskManager.msg7' />';
                    }else if(obj.progress >= 105108 && obj.progress < 105111){
                        htmlstr+='<spring:message code='usercenter.taskManager.msg8' />';
                    }else if(obj.progress == 105111){
                        htmlstr+='<spring:message code='usercenter.taskManager.msg9' />';
                    }
                    var url = "${path}/taskSigning/taskSigning.html?itemId="+obj.itemId+"&type=1";
                    var url2 = "${path}/chatManage/chatMain.html?userType=0&itemId="+obj.itemId;
                    htmlstr+='</em></p>'+
                            '</div>'+
                            '<div class="p_opr">';
                    if(obj.progress==105107 && obj.isbid==101001){
                        htmlstr+='<a  href="'+url+'"><spring:message code='usercenter.taskManager.msg10' /></a>';
                    }
                    if(obj.progress > 105107){
                        htmlstr+='<a   href="'+url2+'" target="_Blank"><spring:message code='usercenter.taskManager.msg11' /></a>';
                    }

                    htmlstr+='</div>'+
                            '</div>'+
                            '<div class="clr"></div>'+
                            '</li>';
                }
                $("#tasks").html(htmlstr);
                var pager = data.pageInfo;
                //分页
                createPage(pager.pageNum, pager.pages, pager.total,type);
                $("#kkpager").show();
            }

        },"json");
    }

    //分页方法
    //currentPage 当前页
    //rows 每页条数
    //total 总数
    function createPage(currentPage, totalPage, totalCount,type) {
        var totalPage = totalPage;
        var totalRecords = totalCount;
        var pageNo = currentPage;
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //总数据条数
            totalRecords: totalRecords,
            //链接前部
            hrefFormer: 'index',
            //链接尾部
            hrefLatter: '',
            //是否显示总页数
            isShowTotalPage: true,
            //是否显示总记录数
            isShowTotalRecords: true,
            //是否显示页码跳转输入框
            isGoPage: true,
            //getLink: function (n) {
            //    return this.hrefFormer + this.hrefLatter + "?pno=" + n;
            //}
            //,
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                //this.selectpage(n);
                initBeanInfo(n, pageSize,type);
                return false;
            },
            lang				: {
                firstPageText			: '<spring:message code="firstPageText"/>',
                firstPageTipText		: '<spring:message code="firstPageTipText"/>',
                lastPageText			: '<spring:message code="lastPageText"/>',
                lastPageTipText			: '<spring:message code="lastPageTipText"/>',
                prePageText				: '<spring:message code="prePageText"/>',
                prePageTipText			: '<spring:message code="prePageTipText"/>',
                nextPageText			: '<spring:message code="nextPageText"/>',
                nextPageTipText			: '<spring:message code="nextPageTipText"/>',
                totalPageBeforeText		: '<spring:message code="totalPageBeforeText"/>',
                totalPageAfterText		: '<spring:message code="totalPageAfterText"/>',
                totalRecordsAfterText	: '<spring:message code="totalRecordsAfterText"/>',
                gopageBeforeText		: '<spring:message code="gopageBeforeText"/>',
                gopageButtonOkText		: '<spring:message code="gopageButtonOkText"/>',
                gopageAfterText			: '<spring:message code="gopageAfterText"/>',
                buttonTipBeforeText		: '<spring:message code="buttonTipBeforeText"/>',
                buttonTipAfterText		: '<spring:message code="buttonTipAfterText"/>'
            }
        },true);
    }
    //获取最近查看历史记录
    function historyTask(){
        var history_task = $.cookie("history_task");
        var htmlstr='';
        if(history_task != null) {
            var arr = history_task.split(",");
            for(var i=0;i<arr.length;i++) {
                var arr2 = arr[i].split(";");
                var price = arr2[3].substring(0,arr2[3].indexOf(".")+3);
                htmlstr+='<li class="clearfix">'+
                        '<div class="p_img"><img src="${path}/'+arr2[1]+'" width="170" height="104"  onclick="window.location=\'${path}/taskdetail/index.html?taskId='+arr2[0]+'\'" style="cursor: pointer" /></div>'+
                        '<div class="p_con clearfix">'+
                        '<h3>'+arr2[2]+'</h3>'+
                        '<div class="p_pcon">'+
                        '</div>'+
                        '<div class="p_money">'+
                        '<p><em class="price">￥'+price+'</em></p>'+
                        '<p><em></em></p>'+
                        '</div>'+
                        '<div class="p_opr">'+
                        '<a href="${path}/taskdetail/index.html?taskId='+arr2[0]+'"><spring:message code='usercenter.taskManager.msg12' /></a>'+
                        '</div>'+
                        '</div>'+
                        '<div class="clr"></div>'+
                        '</li>';
            }
            $("#tasks").html(htmlstr);
        }
        $("#kkpager").hide();
    }
    $(function(){
        initBeanInfo(1,10,'${type}');
    });
</script>

<jsp:include page="../usercenter/leftMenuEnd.jsp"></jsp:include>
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>